package com.jeff.cloud.consumermovie.controller;

import com.jeff.cloud.consumermovie.bean.User;
import com.jeff.cloud.consumermovie.feign.UserFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;

/**
 * @author: jeff
 * @date: 2021/8/6 14:35
 */
@RestController
public class MovieController {
    @Autowired
    private UserFeignClient userFeignClient;
    @GetMapping("/user/{id}")
    public User findById(@PathVariable Long id){
        return this.userFeignClient.findById(id);
    }

    @GetMapping("/get")
    public User get(String username,String password){
        HashMap<String,Object> map = new HashMap<String, Object>();
        map.put("id","1");
        map.put("username",username);
        return this.userFeignClient.get2(map);
    }

    @PostMapping("/post")
    public User post(@RequestBody User user){
        return this.userFeignClient.post(user);
    }
    /*@Autowired
    private RestTemplate restTemplate;
    @GetMapping("/user/{id}")
    public User findById(@PathVariable Long id){
        return this.restTemplate.getForObject("http://localhost:8000/"+id,User.class);
    }

    @Value("${user.userServiceUrl}")
    private String userServiceUrl;
    @GetMapping("/user2/{id}")
    public User findById2(@PathVariable Long id){
        return this.restTemplate.getForObject(this.userServiceUrl+id,User.class);
    }*/
}
